<template>
  <div class="header-info">
    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">头部设置</el-divider>
      </div>
      <el-form-item label="区域高度">
        <el-input-number
          :min="0"
          size="small"
          v-model="optionsInfo.headHeight"
        />
      </el-form-item>
      <el-form-item label="背景颜色">
        <el-color-picker
          size="small"
          show-alpha
          :predefine="predefineColors"
          v-model="optionsInfo.backgroundColor"
        />
      </el-form-item>
      <el-form-item label="医生数量" class="doctor-number" v-if="optionsInfo?.doctorNumber">
        <el-input-number
          :min="1"
          :max="optionsInfo.maxNumber"
          size="small"
          v-model="optionsInfo.doctorNumber"
        />
        <el-tooltip
          class="item"
          effect="dark"
          content="此属性只在模拟环境生效"
          placement="bottom"
        >
          <el-button>
            <i class="el-icon-warning"></i>
          </el-button>
        </el-tooltip>
      </el-form-item>

      <template v-if="(optionsInfo.widgetSign)==='trends2'">
        <el-form-item label="显示医生名字&隐藏候诊患者" class="column-area" label-width="100%">
          <el-switch v-model="optionsInfo['doctorNameShown']"/>
        </el-form-item>
      </template>
    </div>
    <!--科室设置-->
    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">科室&诊室设置</el-divider>
      </div>

      <el-form-item label="是否换行">
        <el-switch v-model="optionsInfo.wrapShow"/>
      </el-form-item>

      <el-form-item label="诊室&科室字号" v-if="!!(optionsInfo.roomNameFontSize)">
        <el-input-number
          :disabled="!(optionsInfo.defaultShowCol).includes('roomName')"
          :min="12"
          size="small"
          v-model="optionsInfo.roomNameFontSize"
        />
      </el-form-item>
    </div>

    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">患者设置</el-divider>
      </div>
      <el-form-item label="就诊患者标题">
        <el-input
          maxlength="2"
          size="small"
          v-model="optionsInfo.currentPatientSign"
        />
      </el-form-item>

      <el-form-item label="候诊患者标题">
        <el-input
          maxlength="2"
          size="small"
          v-model="optionsInfo.waitPatientSign"
        />
      </el-form-item>

      <el-form-item label="候诊类型设置" class="wait-patient-set">
        <el-radio-group
          v-model="optionsInfo.waitPatientType"
          @change="handleChangeType"
        >
          <el-radio
            :label="item.value"
            v-for="item in waitPatientTypeOptions"
            :key="item.value"
          >
            {{ item.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>

      <template v-if="optionsInfo.waitPatientType === 1">
        <el-form-item label="候诊就诊" class="wait-patient-set">
          <el-radio-group
            v-model="optionsInfo.waitMode"
          >
            <el-radio
              :label="item.value"
              v-for="item in options"
              :key="item.value"
            >
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
      </template>

      <template v-if="optionsInfo.waitPatientType === 2">
        <el-form-item label="列表是否滚动">
          <el-switch v-model="optionsInfo.openScroll"/>
        </el-form-item>

        <el-form-item label="滚动速度">
          <el-input-number
            v-model="optionsInfo.waitPatientStep"
            :min="1"
            :max="4"
            size="small"
            class="hide-spin-button"
            :disabled="!optionsInfo.openScroll"
          />
        </el-form-item>

        <el-form-item label="候诊的人数">
          <el-input-number
            v-model="optionsInfo.waitPatientNumber"
            :min="1"
            :max="99"
            size="small"
            class="hide-spin-button"
          />
        </el-form-item>

      </template>

    </div>

    <!-- 二维码设置-->
    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">二维码设置</el-divider>
      </div>

      <el-form-item label="服务号" class="logo-area-set">
        <el-button type="primary" @click="handleSelect('hospitalCode',(optionsInfo.hospitalCode))">服务号</el-button>
        <div class="picture-wrap">
          <template v-if="!!(!!(optionsInfo?.hospitalCode)&&!!(optionsInfo?.hospitalCode?.length)&&!!(optionsInfo?.hospitalCode[0].url))">
            <img :src="`${optionsInfo.hospitalCode[0].url}`" alt="服务号"/>
            <p class="icon-wrap" @click="handleDeletePicture('hospitalCode')">
              <i class="el-icon-close icon-delete"/>
            </p>
          </template>
          <template v-else>
            <div class="el-upload el-upload--text" @click="handleSelect">
              <i class="el-icon-plus avatar-uploader-icon"/>
            </div>
          </template>
        </div>
      </el-form-item>

      <el-form-item label="服务驿站" class="logo-area-set">
        <el-button type="primary" @click="handleSelect('publicCode',(optionsInfo.publicCode))">服务驿站</el-button>
        <div class="picture-wrap">
          <template  v-if="!!(!!(optionsInfo?.publicCode)&&!!(optionsInfo?.publicCode?.length)&&!!(optionsInfo?.publicCode[0].url))">
            <img :src="`${optionsInfo.publicCode[0].url}`" alt="服务驿站"/>
            <p class="icon-wrap" @click="handleDeletePicture('publicCode')">
              <i class="el-icon-close icon-delete"/>
            </p>
          </template>
          <template v-else>
            <div class="el-upload el-upload--text" @click="handleSelect">
              <i class="el-icon-plus avatar-uploader-icon"/>
            </div>
          </template>
        </div>
      </el-form-item>
    </div>


    <!--选择图片的弹层-->
    <UpdatePicture
      :visible="pictureInfo.visible"
      :info="pictureInfo.info"
      @handleCancel="handleCancel"
      @handleSure="handleSure"
    />
  </div>
</template>

<script>
import constantDic from "@/utils/vue-i18n/lang/zh-CN";
import roomNameKeyEditor
  from "@sc/templateDetails/modules/homeRight/property-editor/module/scene-edit/basicInfo/roomNameKey-editor.vue";
import * as types from "@c/public/form-designer/devType/datas-types";
import UpdatePicture from "@c/public/layer/template/updatePicture/index.vue";

export default {
  name: "DRCTrendsConfig3-editor",
  components: {UpdatePicture, roomNameKeyEditor},

  componentName: "DRCTrendsConfig3-editor",

  mixins: [],

  props: {
    designer: Object,
    selectedWidget: Object,
    optionModel: Object,
  },

  inject: ["serverFieldList", "getDesignerConfig"],

  data() {
    return {
      radio: 1,
      optionsInfo: Object(),
      constantDic: constantDic,
      predefineColors: types["predefineColors"],
      pictureInfo: {
        info:Object(),
        visible: false
      },
      formEditorInfo: {
        info:Object(),
        visible: false
      },
      waitPatientTypeOptions: [
        {
          value: 1,
          label: "诊室等候",
        },
        {
          value: 2,
          label: "候诊列表",
        },
      ],
      options: [
        {
          value: 1,
          label: "叫1等1",
        },
        {
          value: 2,
          label: "叫1等2",
        },
        {
          value: 3,
          label: "叫1等3",
        },
        {
          value: 4,
          label: "叫1等4",
        }
      ],
    };
  },

  methods: {
    handleChangeType(val) {
      if (val === 2) {
        this.optionsInfo.openScroll = false;
        this.optionsInfo.waitPatientStep = 1;
        this.optionsInfo.waitPatientNumber = 4;
      } else if (val === 1) {
        this.optionsInfo.waitMode = 1;
      }
    },

    // 改变可是和诊室
    handleChangeDept(event, key) {
      console.log(event)
      let val = this.$lodash.uniqBy(event);
      if (val?.length === 1) {
        Reflect.set((this.optionsInfo), 'deptNameFontSize', 150);
        Reflect.set((this.optionsInfo), 'roomNameFontSize', 150)
      } else {
        Reflect.set((this.optionsInfo), 'deptNameFontSize', 92);
        Reflect.set((this.optionsInfo), 'roomNameFontSize', 120)
      }
      Reflect.set(this.optionsInfo, 'defaultShowCol', val)
    },

    // 选择图片
    handleSelect(val,content) {
      let params = Object();
      switch (val) {
        case 'publicCode':
        case 'hospitalCode':
          let content2 = !!((content?.length)&&(content[0]?.url))? content : ''
          Reflect.set(params,'updataType',val);
          Reflect.set(params,'type','image');
          Reflect.set(params,'multiple',false);
          Reflect.set(params,'content',content2 || '')
          Reflect.set((this.pictureInfo), 'visible', true);
          Reflect.set((this.pictureInfo), 'info', params);
          break
        case 'describeContent':
          Reflect.set(params,'updataType',val);
          Reflect.set(params,'content',content || '')
          Reflect.set((this.formEditorInfo), 'visible', true);
          Reflect.set((this.formEditorInfo), 'info', params);
          break
      }
    },

    // 删除图片
    handleDeletePicture(key) {
      Reflect.set((this.optionsInfo), key,'')
    },

    // 关闭弹层
    handleCancel() {
      Reflect.set(this.pictureInfo, 'visible', false);
      Reflect.set(this.formEditorInfo, 'visible', false)
    },

    // 更新就的数据
    handleSure(valInfo) {
      let {key, val} = valInfo;
      Reflect.set((this.optionsInfo), key, val);
    },

  },

  watch: {
    // 组件的所有信息
    optionModel: {
      handler: function (val) {
        this.optionsInfo = val[val.config];
      },
      deep: true,
      immediate: true,
    },
  },
};
</script>

<style lang="scss" scoped>
.column-area,
.wait-patient-set {
  display: flex;
  flex-direction: column;

  :deep(.el-form-item__labe) {
    width: 100% !important;
  }

  :deep(.el-form-item__content) {
    margin-left: 0 !important;

    .el-radio-group {
      display: flex;
      flex-direction: column;

      .el-radio {
        padding: 10px 0;
      }
    }

    .el-checkbox-group {
      display: flex;
      flex-direction: column;
    }

  }
}

//医生数量
.doctor-number {
  display: flex;
  flex-direction: column;

  :deep(.el-form-item__label) {
    width: 100% !important;
  }

  :deep(.el-form-item__content) {
    margin-left: 0 !important;
    display: flex;
    flex-direction: row;
    flex-grow: 1;

    .el-input-number {
      flex-shrink: 1;
      width: 150px;
    }

    .el-button {
      color: #e58602;
      font-size: 18px;
      flex-shrink: 0;
      padding: 0 15px;
      border-color: transparent !important;
      background: transparent !important;
    }


  }
}


.logo-area-set {
  display: flex;
  position: relative;
  flex-direction: column;

  :deep(.el-form-item__label) {
    width: 100% !important;
    display: flex;
    @include fontWeight()
  }

  :deep(.el-form-item__content) {
    margin-left: 0 !important;

    .el-button {
      position: absolute;
      top: -30px;
      right: 0;
    }

    .picture-wrap {
      margin-top: 10px;
      position: relative;
      overflow: hidden;
      width: 108px;
      height: 108px;

      img {
        border-radius: 4px;
        overflow: hidden;
        width: 100%;
      }

      .icon-wrap {
        width: 20px;
        height: 20px;
        display: flex;
        align-items: center;
        align-self: center;
        justify-content: center;
        background: rgba(0, 0, 0, 0.4);
        position: absolute;
        top: 0;
        left: 0;
        cursor: pointer;
        border-radius: 0 0 100px 0;

        .icon-delete {
          font-weight: bold;
          color: rgba(255, 255, 255, 0.8);
        }
      }

      .el-upload {
        background-color: #fbfdff;
        border: 1px dashed #c0ccda;
        border-radius: 6px;
        box-sizing: border-box;
        width: 108px;
        height: 108px;
        cursor: pointer;
        line-height: 116px;
        vertical-align: top;

        &:hover {
          border-color: #409eff;
          color: #409eff;
        }

        .el-icon-plus {
          font-size: 1.25rem;
          color: rgba(0, 0, 0, 0.45);
        }
      }
    }

  }
}
</style>
